package com.zhangtai.utils;

import com.zhangtai.enums.ErrCodeEnum;
import lombok.Data;

import java.io.Serializable;


/**
 * @Classname R
 * @Description 响应信息主体
 * @Author 李号东 lihaodongmail@163.com
 * @Date 2019-03-27 21:54
 * @VeRion 1.0
 */
@Data
public class R<T> implements Serializable {

    private static final long serialVeRionUID = 1L;


    public final static Integer isOk = 200;
    private Boolean flag;
    private int status = 200;
    private String error;
    private T data;


    public R() {
    }

    public R( Boolean flag,Integer code, String message, Object data) {

        this.flag=flag;
        this.status = code;
        this.error = message;
        this.data = (T)data;
    }

    public R(  Boolean flag,Integer code, String message) {
        this.flag=flag;
        this.status = code;
        this.error = message;
    }



    public static R ok(){

        return new R(true,200,"操作成功");
    }


    public static R ok(Object data){
        return new R(true,200,"操作成功",data);
    }

//    public static R ok(String msg,Object data){
//        return new R(true,200,msg,data);
//    }


    public static R error(){
        return new R(false,500,"操作失败");
    }

    public static R error(String message){
        return new R(false,500,message);
    }


    public static R error(Integer code, String message){
        return new R(false,code,message);
    }

    public static R error(ErrCodeEnum errCodeEnum){

        return new R(false,errCodeEnum.getCode(),errCodeEnum.getErrorMessage());
    }






  
}
